// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   ServletUtils.java

package dale.web.core.filter;

import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ServletUtils
{

    public ServletUtils()
    {
    }

    public static void log(HttpServletRequest request)
    {
        logProperteis(request);
        logRequestHeaders(request);
        logRequestParameters(request);
        logRequestAttributes(request);
        logSessionAttributes(request);
    }

    public static void logProperteis(HttpServletRequest request)
    {
        StringBuffer buf = new StringBuffer();
        buf.append("* Request Details");
        String URL = request.getRequestURL().toString();
        String method = request.getMethod();
        buf.append((new StringBuilder("\n - URL : ")).append(URL).toString());
        buf.append((new StringBuilder("\n - method : ")).append(method).toString());
        log.info(buf);
    }

    public static void logRequestHeaders(HttpServletRequest request)
    {
        StringBuffer buf = new StringBuffer();
        buf.append("\n* Headers List");
        String headerName;
        String headerValue;
        for(Enumeration enu = request.getHeaderNames(); enu.hasMoreElements(); buf.append((new StringBuilder("\n - ")).append(headerName).append(" : ").append(headerValue).toString()))
        {
            headerName = (String)enu.nextElement();
            headerValue = request.getHeader(headerName);
        }

        log.debug(buf);
    }

    public static void logRequestParameters(HttpServletRequest request)
    {
        StringBuffer buf = new StringBuffer();
        buf.append("\n* Parameters List\n");
        SortedMap sMap = Collections.synchronizedSortedMap(new TreeMap(request.getParameterMap()));
        synchronized(sMap)
        {
            for(Iterator iterator = sMap.keySet().iterator(); iterator.hasNext();)
            {
                String key = (String)iterator.next();
                String values[] = (String[])sMap.get(key);
                String as[];
                int j = (as = values).length;
                for(int i = 0; i < j; i++)
                {
                    String value = as[i];
                    buf.append((new StringBuilder(String.valueOf(key))).append(" : ").append(value).toString());
                }

            }

        }
        log.debug(buf);
    }

    public static void logRequestAttributes(HttpServletRequest request)
    {
        StringBuilder sb = new StringBuilder("\n* Request Attributes List");
        String name;
        Object value;
        for(Enumeration enu = request.getAttributeNames(); enu.hasMoreElements(); sb.append((new StringBuilder("\n - ")).append(name).append(" : ").append(value).toString()))
        {
            name = (String)enu.nextElement();
            value = request.getAttribute(name);
        }

        log.debug(sb);
    }

    public static void logSessionAttributes(HttpServletRequest request)
    {
        StringBuilder sb = new StringBuilder("\n* Session Attributes List");
        HttpSession session = request.getSession(false);
        if(session == null)
            return;
        String name;
        Object value;
        for(Enumeration enu = session.getAttributeNames(); enu.hasMoreElements(); sb.append((new StringBuilder("\n - ")).append(name).append(" : ").append(value).toString()))
        {
            name = (String)enu.nextElement();
            value = session.getAttribute(name);
        }

        log.debug(sb);
    }

    private static Log log = LogFactory.getLog(ServletUtils.class);

}
